/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
 * Copyright 2020 Pelican Mapping
 * http://osgearth.org
 *
 * osgEarth is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
#ifndef OSGEARTH_COMMON_H
#define OSGEARTH_COMMON_H 1

#include <osgEarth/Export>
#include <osgEarth/Notify>
#include <osg/Version>
#include <osg/ref_ptr>
#include <osg/Referenced>
#include <osg/Math>
#include <memory>

// define the OSG Version checks for older OSG versions

#ifndef OSG_MIN_VERSION_REQUIRED
#  define OSG_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH))))
#  define OSG_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION<MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION<MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION<PATCH))))
#  define OSG_VERSION_LESS_OR_EQUAL(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION<MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION<MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION<=PATCH))))
#  define OSG_VERSION_GREATER_THAN(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>PATCH))))
#  define OSG_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH))))
#endif

// text inlining macro
#define OE_MULTILINE(...) #__VA_ARGS__

// expandable comment for macros (only works in MSVC)
// TODO: Fails when using Qt - reevaluate later
//#ifdef _MSC_VER
#if 0
#define OE_COMMENT(STR) / ## ** #STR * ## /
#else
#define OE_COMMENT(STR)
#endif

/** osgEarth core */
namespace osgEarth
{
    // application-wide unique ID.
    typedef int UID;

    // reference counted unique UID.
    struct OSGEARTH_EXPORT RefUID : public osg::Referenced {
        RefUID() : _uid(0) { }
        RefUID(UID uid) : _uid(uid) { }
        operator UID() const { return _uid; }
        UID _uid;
    };

    // Global initializer for osgEarth - call this if you are setting up
    // windows and views prior to using osgEarth
    extern OSGEARTH_EXPORT void initialize();
}

#ifdef _MSC_VER
// VS ignores
#pragma warning (disable: 4224)
#pragma warning (disable: 4180)
#endif

#include "osgEarth/BuildConfig.h"

// FINAL keyword for C++11
#ifdef OSGEARTH_CXX11
#define OSGEARTH_FINAL final
#else
#define OSGEARTH_FINAL
#endif

// Sringification
#define OE_STRINGIFY_0(x) #x
#define OE_STRINGIFY(x) OE_STRINGIFY_0(x)

#endif // OSGEARTH_COMMON_H
